import { handleActions } from "redux-actions";
import {
    GET_USERS,
    SET_CUR_PAGE_USERS,
    SET_EACH_PAGE_USERS
} from "../types";
import _ from "lodash";
const initData = {
    curPage: 1,
    eachPage: 10,
    total: 0,
    maxPage: 10,
    rows: []
}
//创建
export const users = handleActions({
    [GET_USERS]: (state, { payload }) => {
        const { total, maxPage, rows } = payload;
        return _.assign({}, state, {
            total,
            maxPage,
            rows,
        });
    },
    [SET_CUR_PAGE_USERS]: (state, { payload }) => {
        const { curPage } = payload;
        // console.log(curPage);
        const $state = _.clone(state);
        $state.curPage = curPage;
        return $state;
    },

    [SET_EACH_PAGE_USERS]: (state, { payload }) => {

        const { eachPage } = payload;
        const $state = _.clone(state);
        $state.eachPage = eachPage;
        // $state.rows=[];
        return $state;
    }
}, initData);
